<template>
  <div id="resources">
    <div class="search">
      <div class="searchname">课程搜索</div>
      <div class="searchbox">
        <Input class="search-input"
               search
               enter-button
               placeholder=""
               v-model="videoName"
               @on-search="search" />
        <Select v-model="courseType"
                clearable
                class="search-select">
          <Option v-for="item in cityList"
                  :value="item.value"
                  :key="item.value">{{ item.label }}</Option>
        </Select>
      </div>
      <div class="condition">
        <span class="name">综合排序:</span>
        <ul class="order">
          <li :class="{'active':currentIndex===0}"
              @click="selectItem(0)">按时间降序</li>
          <li :class="{'active':currentIndex===1}"
              @click="selectItem(1)">按时间升序</li>
          <li :class="{'active':currentIndex===2}"
              @click="selectItem(2)">按播放次数升序</li>
          <li :class="{'active':currentIndex===3}"
              @click="selectItem(3)">按播放次数降序</li>
        </ul>
      </div>
    </div>
    <div class="content">
      <ul class="wrap clearfix">
        <li class="item"
            v-for="item in dibbling">
          <div class="video">
            <video src="http://vjs.zencdn.net/v/oceans.mp4"
                   poster="../../assets/img/live-poster.jpg"></video>
            <div class="mask">
              <img src="../../assets/img/button-play.png"
                   @click="goReplay(item)">
            </div>
          </div>
          <div class="videoinfo">
            <div class="line clearfix">
              <div class="name">{{item.courseName}}</div>
            </div>
            <div class="line clearfix">
              <div class="teacher">讲师：
                <span>{{item.name}}</span>
              </div>
              <div class="type">类型：
                <span>{{item.courseType==1?'案例联席':'普通教学'}}</span>
              </div>
            </div>
            <div class="line clearfix">
              <div class="time"><img src="../../assets/img/time.png">{{item.courseStartTime.slice(0,19)}}</div>
              <div class="click-times">点击次数：
                <span>{{item.playTimes}}</span>次</div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="page">
      <Page :total="total" />
    </div>
  </div>
</template>
<script>
import { queryTeachingResultsManage } from '@/api/management.js'
import { updatePlayTimes, queryMyClass } from '@/api/data.js'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      currentIndex: -1,
      pageSize: 16,
      pageIndex: 1,
      dibbling: [],
      total: 0,
      cityList: [
        {
          value: '2',
          label: '全部'
        },
        {
          value: '1',
          label: '案例联席'
        },
        {
          value: '0',
          label: '普通教学'
        },
      ],
      videoName: '',
      courseType: '',
      orderName: ''
      //       orderName = "" 初始化   时间倒序                                                                                                  
      // orderName ="timedesc"  时间倒序      
      // orderName ="timeasc" 时间正序  
      // orderName = "playTimesDesc"点播次数倒序
      // orderName="playTimesAsc"点播次数正序 	                                                                                
    }
  },
  mounted () {
    this.getList()
  },
  computed: {
    ...mapState({
      hasGetInfo: state => state.user.hasGetInfo,
      userName: state => state.user.userName,
      name: state => state.user.name,
      userId: state => state.user.userId,
      avatorImgPath: state => state.user.avatorImgPath,
      roleName: state => state.user.roleName,
      roleId: state => state.user.roleId,
    }),
  },
  methods: {
    search () {
      this.getList()
    },
    // 筛选
    selectItem (index) {
      this.currentIndex = index
      switch (index) {
        case 0:
          this.orderName = "timedesc"
          this.getList()
          break;
        case 1:
          this.orderName = "timeasc"
          this.getList()
          break;
        case 2:
          this.orderName = "playTimesDesc"
          this.getList()
          break;
        case 3:
          this.orderName = "playTimesAsc"
          this.getList()
          break;
      }
    },
    getList () {
      const params = {
        pageNum: this.pageIndex,
        pageSize: this.pageSize,
        courseType: this.courseType,
        courseName: this.videoName,
        putinStatus: '',
        startDate: '',
        endDate: '',
        orderName: this.orderName,
        userId: this.userId
      }
      queryMyClass(params).then(({ data }) => {
        if (data.rows.length > 0) {
          this.dibbling = data.rows
          this.dibbling.map((item) => {
            item.courseStartTime.slice(0, 10)
          })
          this.total = data.total
        } else {
          this.dibbling = []
          this.total = 0
        }
      })
    },
    goReplay (item) {
      let routeData = this.$router.resolve({
        name: 'replay',
        // query: params,
        params: { item: item }
      })
      sessionStorage.setItem('replayData', item.videoFileName)
      updatePlayTimes(item.videoId).then(res => {
        if (res.data == 'success') {
          this.getList()
          window.open(routeData.href, '_blank')
        }
      })

    },
  }
}
</script>
<style lang="scss">
#resources {
  .search {
    display: flex;
    height: 40px;
    line-height: 40px;
    margin-bottom: 20px;
    .searchname {
      width: 70px;
      height: 32px;
      font-size: 13px;
    }
    .searchbox {
      display: flex;
      height: 40px;
      font-size: 0;
      .search-input {
        position: relative;
        width: 150px;
        top: 4px;
        margin-right: 5px;
      }
      .search-select {
        width: 100px;
        position: relative;
        top: 4px;
      }
    }
    .condition {
      display: flex;
      font-size: 16px;
      height: 40px;
      padding-left: 40px;
      .name {
        padding: 0 10px;
        font-size: 13px;
      }
      .order {
        display: flex;
        li {
          padding: 0 10px;
          font-size: 13px;
          box-sizing: border-box;
          cursor: pointer;
          &:hover {
            color: #57a3f3;
            border-bottom: 2px solid #57a3f3;
          }
          &.active {
            color: #57a3f3;
            border-bottom: 2px solid #57a3f3;
          }
        }
      }
    }
  }
  .content {
    margin: 0 auto;
    .wrap {
      width: 100%;
      .item {
        float: left;
        width: calc(100% / 3);
        padding: 0 10px 20px;
        .video {
          width: 100%;
          height: 180px;
          position: relative;
          border-radius: 10px;
          overflow: hidden;
          video {
            width: 100%;
            height: 100%;
          }
          .mask {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.1);
            font-size: 0;
            img {
              width: 60px;
              height: 60px;
              position: absolute;
              left: 50%;
              top: 50%;
              transform: translateX(-50%) translateY(-50%);
              transition: all 0.3s;
              cursor: pointer;
              &:hover {
                width: 70px;
                height: 70px;
              }
            }
          }
        }
        .videoinfo {
          padding-top: 10px;
          .line {
            .name {
              float: left;
              font-size: 16px;
              color: #484d69;
            }
            .teacher {
              float: left;
              font-size: 12px;
              color: #8a92a5;
              line-height: 20px;
              span {
                font-size: 14px;
                color: #484d69;
              }
            }
            .type {
              float: right;
              font-size: 12px;
              line-height: 20px;
              color: #8a92a5;
              span {
                font-size: 14px;
                color: #484d69;
              }
            }
            .time {
              float: right;
              font-size: 12px;
              line-height: 20px;
              color: #8a92a5;
              img {
                width: 13px;
                vertical-align: -2px;
                margin-right: 5px;
              }
            }
            .click-times {
              float: left;
              font-size: 12px;
              line-height: 20px;
              color: #8a92a5;
              span {
                font-size: 14px;
                color: #484d69;
              }
            }
          }
        }
      }
    }
  }
  .page {
    text-align: center;
    padding-top: 40px;
  }
}
</style>

